package com.xiangxiao.rpan.storage.controller;

import com.xiangxiao.rpan.storage.constant.ResponseCode;
import com.xiangxiao.rpan.storage.constant.ResponseMessage;
import com.xiangxiao.rpan.storage.dto.FileListConfigDto;
import com.xiangxiao.rpan.storage.dto.JsonObject;
import com.xiangxiao.rpan.storage.exception.StorageExcetion;
import com.xiangxiao.rpan.storage.service.StorageSourceService;
import com.xiangxiao.rpan.storage.vo.StorageSourceConfigVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @auther xiangxiao
 * @email 573768011@qq.com
 * @data 2024/1/4 16:36
 */
@RequestMapping("/api/site")
@RestController
public class SiteController {
  @Resource
  private StorageSourceService storageSourceService;
  @PostMapping("/config/storage")
  public JsonObject queryStorageConfigs (@Valid @RequestBody FileListConfigDto fileListConfigDto) {
    try {
      StorageSourceConfigVo vo = storageSourceService.getStorageConfigSource(fileListConfigDto);
      return new JsonObject(ResponseMessage.QUERY_STORAGE_CONFIG_SUECCESS, ResponseCode.OK, vo);
    } catch (StorageExcetion e) {
      e.printStackTrace();
      return new JsonObject(ResponseMessage.QUERY_STORAGE_CONFIG_FAILED, ResponseCode.QUERY_STORAGE_CONFIG_FAILED);
    }
  };
}
